define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		//数据
		function get_data_list(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"beagenter":[{"info_id":"001","brand_id":"001","brand_name":"世博","region":[{"id":"001","name":"江苏"},{"id":"088","name":"南京"},{"id":"055","name":"下关"}],"apply_time":"2017-3-5"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		//发布经销
		function get_data_edit(result) {
            if(HTTP_ISLOGIC) {
                result = '{"success": true,"msg": "","result": {"info_id":"001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

		//根据id查找
		function get_data_findById(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"info_id":"001","cat_type":[{"id":"001"},{"id":"002"},{"id":"003"}],"requirement":"这是我的需求描述喔，我需要一批工具。","region":[{"id":"566","name":"广西"},{"id":"617","name":"桂林"},{"id":"621","name":"七星区"}],"money":"20000","phone":"13617739888"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

		//返回信息
		return {
			//数据
				getList: function(nPage, pagelimit, callback,calldone) {
				Http.post({
						method: 'member.beagenter.getlist',
						nPage: nPage,
						pagelimit: pagelimit
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_list(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
						if(calldone)
                   			calldone();
					});
			},
			//发布经销
                beagenter_edit: function(info_id, cat_type_id,region_id,reason,capital,phone, callback) {
                    var params=new Object();
                    params.info_id=info_id;
                    params.cat_type_id=cat_type_id;
                    params.region_id=region_id;
                    params.reason=reason;
                    params.capital=capital;
                    params.phone=phone;
                    params=JSON.stringify(params);
                Http.post({
                        method: 'member.beagenter.edit',
                        updateParams: params
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_edit(result));
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });
            },

           findById: function(info_id, callback) {
				Http.post({
						method: 'member.beagenter.detail',
						info_id: info_id
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_findById(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			delete_info_id:function(info_id,callback){
			    Http.post({
                        method: 'member.beagenter.delete',
                        info_id: info_id
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(result);
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    }
                );
			}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Wanttodistributor", factory);
});